﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RN.Componentes;
using RN.Entidades;

namespace Sitio
{
    public partial class Proveedor : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack) 
            {
                Cargar_grid();
            }
        }
        public void Cargar_grid()
        {
            List<RN.Entidades.Proveedor> obj = CProveedor.Traer();
            grdProveedores.DataSource = obj;
            grdProveedores.DataBind();
        }
        protected void ResultGrid_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            int id = Convert.ToInt32(e.CommandArgument);


            if (e.CommandName == "Editar")
            {
                RN.Entidades.Proveedor p = CProveedor.TraerXId(id);
                tbNombre.Text = p.SNOMBRE1;
                tbTelefono.Text = p.STELEFONO1;
                tbDireccion.Text = p.SDIRECCION1;
                tbDescripcion.Text = p.SDESCRIPCION_DSC1;
            }
            else
            {
                if (e.CommandName == "Eliminar")
                {
                    if (CProveedor.Eliminar(id))
                    {
                    }
                    else
                    {

                    }
                }
            }
        }
        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void btNuevo_Click(object sender, EventArgs e)
        {
            pnlNuevo.Visible= true;
            pnlBuscar.Visible = false;
        }

        protected void btBuscar_Click(object sender, EventArgs e)
        {
            pnlNuevo.Visible = false;
            pnlBuscar.Visible = true;
        }
    }
}